<template>
  <div style="position:relative">
    <!-- :params="fetchParams" -->
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="list"
      :isColumnFilter="false"
      :isToperInfo="false"
      :isSelectColumn="false"
      :onSyncTableData="syncTableFun"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <!-- <template slot="controls" slot-scope="props">
           <el-button
             size="small"
             type="primary"
             icon="el-icon-plus"
             @click="addPjxmHandle()"
           >新增</el-button>
         </template> -->
    </FilterTable>
    <!-- <BaseDialog
      :visible.sync="visiblePjxm"
      title="备件选择"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
      destroyOnClose>
      <AddPjxm  ref="addPjxm" @closePj="closeAdddpjxm" />
    </BaseDialog> -->
  </div>
</template>
<script>
// import AddPjxm from '../addXM/addpjxm';
import { dictionary } from '@/utils/dictMixin';
import { detailsPjxm, getStorageList, getPartitionList } from '@/api/repair/repair/activitesManage';
// import { getFwhdPjxmList , getFwhdCkdmList ,getFwhdSfList} from '@/api/repair/repairReception/customer/activity.js';
let _this;
export default {
  name: 'Pjxm',
  components: {
    // AddPjxm
  },
  mixins: [dictionary],
  props: ['detaildata'],
  data() {
    // this.BaseTable = null;
    return {
      visiblePjxm: false,
      columns: this.createTable(),
      fetchApi: '',
      // fetchParams: { xhrAbort: false},
      list: [],
      tableData: []
    };
  },
  created() {
    _this = this;
    _this.getPartitionList();
    _this.getStorageList();
    _this.detailsPjxm();
  },
  // mounted() {
  //   this.BaseTable = this.$refs.basetable.$refs.pageTable;
  // },
  methods: {
    // 获取收费区分下拉框
    async getPartitionList() {
      const res = await getPartitionList();
      this.columns[4].editItems = res.data.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
    },
    // 仓库名称下拉框
    async getStorageList() {
      const res = await getStorageList();
      this.columns[1].editItems = res.data.map(x => ({ value: x.STORAGE_CODE, text: x.STORAGE_NAME }));
    },
    // 获取回显数据方法
    async detailsPjxm() {
      let res = await detailsPjxm(this.detaildata);
      // PART_QUANTITY   备件数量
      // PART_SALES_PRICE备件销售单价
      // PART_SALES_AMOUNT备件销售金额
      // DISCOUNT折扣率
      // PART_SALES_AMOUNT_DISCOUNT折扣后金额合计
      res.data.rows.forEach(x => {
        // x.SALES_PRICE = x.PART_SALES_PRICE
        if (isNaN(Number(x.DISCOUNT))) {
          x.PART_SALES_AMOUNT_DISCOUNT = 0;
        } else {
          x.PART_SALES_AMOUNT_DISCOUNT = Number(x.PART_SALES_AMOUNT) * Number(x.DISCOUNT);
        }
        if(x.CHARGE_PARTITION_CODE == 'S'||x.CHARGE_PARTITION_CODE == 'N'){
          x.PART_SALES_AMOUNT_DISCOUNT = 0;
        }
      });
      _this.$refs.table.$refs.pageTable.EXECUTE_INSERT(res.data.rows);
    },
    ceshi(val) {
      _this.$emit('changetwo', _this.list);
    },
    // 传给父组件的数据
    syncTableFun(val) {
      this.tableData = val;
    },
    // 关闭子弹框
    // closeAdddpjxm (val) {
    //   this.visiblePjxm = false
    //   this.getStorageList()
    //   if (val!=false){
    //     this.$refs.table.$refs.pageTable.EXECUTE_INSERT(val)
    //   }
    // },
    // 打开子弹框
    // addPjxmHandle () {
    //   this.visiblePjxm = true
    // },
    // 维修材料表单数据删除
    delete(val) {
      let a = [];
      a.push(val);
      this.$refs.table.$refs.pageTable.EXECUTE_DELETE(a);
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //     title: '操作',
        //     dataIndex: 'column-action',
        // },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          filterItems: [],
          disabled: true,
          editable: true,
          editType: 'select',
          editItems: []
          // render: props => {
          //   return <span>{this.func(props.row.STORAGE_CODE,2)}</span>;
          //   }
        },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          sorter: true
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          sorter: true
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filterItems: [],
          editable: true,
          disabled: true,
          editType: 'select',
          editItems: []
          // render: props => {
          //   return <span>{this.func(props.row.CHARGE_PARTITION_CODE,5)}</span>;
          //   }
        },
        {
          title: '主要备件',
          dataIndex: 'IS_MAIN_PART',
          sorter: true,
          filterItems: []
          // render: props => {
          //   return <span>{this.createDictText(props.row.IS_MAIN_PART, '1278')}</span>;
          //   }
        },
        {
          title: '维修项目代码',
          dataIndex: 'LABOUR_CODE',
          sorter: true
        },
        {
          title: '计量单位名称',
          dataIndex: 'UNIT_CODE',
          sorter: true
        },
        {
          title: '备件数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true,
          summation: true
        },
        {
          title: '备件销售单价',
          dataIndex: 'PART_SALES_PRICE', // 与SALES_PRICE相等
          sorter: true,
          precision: 2,
          summation: true
        },
        {
          title: '备件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          sorter: true,
          precision: 2,
          summation: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true
        },
        {
          title: '折扣后金额合计',
          dataIndex: 'PART_SALES_AMOUNT_DISCOUNT',
          sorter: true,
          precision: 2,
          summation: true
        },
        {
          title: '最新进货价',
          dataIndex: 'LATEST_PRICE', // LATEST_PRICE  目前   要修改的值。。。
          sorter: true,
          precision: 2,
          summation: true
        },
        {
          title: '销售单价',
          dataIndex: 'SALES_PRICE',
          sorter: true,
          precision: 2,
          summation: true
        },
        {
          title: '备件成本单价',
          dataIndex: 'PART_COST_PRICE', // COST_PRICE
          sorter: true,
          precision: 2,
          summation: true
        },
        {
          title: '备件成本金额',
          dataIndex: 'PART_COST_AMOUNT', // COST_AMOUNT
          sorter: true,
          precision: 2,
          summation: true
        }
      ];
    },
    async getFwhdPjxmList(row) {
      const res = await getFwhdPjxmList(row, {
        creditTimes: 1.0,
        afterlabour: 0,
        zkAmountLabour: 0,
        afterDiscountAmountPart: 0,
        zkAmountPart: 0,
        fag: 'U',
        labourList: '',
        partList: '',
        subjoinList: '',
        modelList: '',
        vehicleList: '',
        order: 'asc',
        limit: 10,
        offset: 0,
        dmsFuncId: 35100010,
        _: 1565681747515
      });
      this.list = res.rows;
    },
    async getFwhdCkdmList() {
      const res = await getFwhdCkdmList();
      this.columns[2].filterItems = res.map(x => ({ value: x.STORAGE_CODE, text: x.STORAGE_NAME }));
    },
    async getFwhdSfList() {
      const res = await getFwhdSfList();
      this.columns[6].filterItems = res.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
    },
    func(val, num) {
      if (val) {
        const res = this.columns[num].filterItems.find(x => x.value == val);
        return res.text;
      }
    }
  }
};
</script>
